﻿using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.U2D;

public class SpriteManager : MonoSingleton<SpriteManager>
{   
    public readonly Dictionary<string,SpriteAtlas> dictAtlas = new Dictionary<string, SpriteAtlas>();
    public override void Initialize()
    {
        base.Initialize();
    }

    public Sprite LoadSpriteAtlas(string strAtlasName,string spriteName)
    {
        SpriteAtlas atlas;
        if (dictAtlas.TryGetValue(strAtlasName, out atlas))
        {
            return atlas.GetSprite(spriteName);
        }
        else
        {
           atlas = Resources.Load<SpriteAtlas>("Atlas/"+strAtlasName);
           if (atlas != null)
           {
               dictAtlas.Add(strAtlasName,atlas);
               return atlas.GetSprite(spriteName);
           }
        }

        return null;
    }

    public override void Release()
    {
        dictAtlas.Clear();
        base.Release();
    }
}
